package com.example.workassignback.Controller;

import com.example.workassignback.annotation.CurrentUser;
import com.example.workassignback.serviceImpl.service.UserService;
import com.example.workassignback.utils.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@Controller
@CrossOrigin
@RequestMapping("/user")
public class UserController {

    @Autowired
    private UserService userService;

    @PostMapping("/login")
    @ResponseBody
    public Result userLogin(@RequestBody Map<String, ?> map) {
        String cardId = (String) map.get("cardId");
        String password = (String) map.get("password");
        return userService.userLogin(cardId, password);
    }

    @PostMapping("/register")
    @ResponseBody
    public Result userRegister(@RequestBody Map<String, ?> map) {
        String cardId = (String) map.get("cardId");
        String password = (String) map.get("password");
        String name = (String) map.get("name");
        String phone = (String) map.get("phone");

        return userService.userRegister(cardId, password, phone, name, "Patient");
    }

    @PostMapping("/test")
    @ResponseBody
    public String test(@CurrentUser String id) {
        return id;
    }
}
